/*
* File: unitialized_copy.cpp
* 测试用例修改自泛型编程和stl 侯捷译 10.4 内存管理基本元素
*/
#include "Allocator.h"
#include <iostream>
#include <algorithm>
class Int {
public:
	Int (int x) : val(x) { std::cout << "Int(" << val << ")" << std::endl;}
	~Int() { val = 0; std::cout << "~Int()" << std::endl;}
	int get() const { return val; }
	
private:
	int val;
};

void display(const Int & x)
{
	std::cout << x.get() << std::endl;
}

int main()
{
	int A1[] = {1, 2, 3, 4, 5, 6, 7};
	const int N = sizeof(A1) / sizeof(int);

	Int * A2 = (Int *) malloc(N * sizeof(Int));
	Allocator<Int> test;
	Int * end = test.uninitialized_copy(A1, A1 + N, A2);
	std::for_each(A2, end, display);
}
